package com.pipayshop.config;

import com.pipayshop.filter.JwtTokenUserInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@Slf4j
public class CorsConfig implements WebMvcConfigurer {
    @Autowired
    JwtTokenUserInterceptor jwtTokenUserInterceptor;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**").addResourceLocations("file:pipayshop-api/src/main/resources/static/images/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        registry.addInterceptor(jwtTokenUserInterceptor)
                .addPathPatterns("/pipayshopapi/**")
//                .addPathPatterns("/pipayshopapi/transaction-record/getRecordTransaction/**", "/pipayshopapi/transaction-record/recordTransaction/**")
                .excludePathPatterns("/pipayshopapi/user-info/**")
                .excludePathPatterns("/pipayshopapi/account-info/selectAllTradinRate")
                .excludePathPatterns("/pipayshopapi/hotel_manger/login")
                .excludePathPatterns("/pipayshopapi/hotel_manger/register")
                .excludePathPatterns("/pipayshopapi/store-info/getSecondDistrictList/{countryCode}")
                .excludePathPatterns("/pipayshopapi/store-info/getThirdDistrictList/{countrySecondId}")
                .excludePathPatterns("/pipayshopapi/store-info/getFourthDistrictList/{countryThirdId}");
    }


}